<?php

class Student_Model_DbTable_Course extends Zend_Db_Table_Abstract {

	protected $_name = 'student_course';

        //returns all the courses from all the users at the sametime

        
        public function getCourse($id)
        {
            $id = (int)$id;
            $row = $this->fetchRow('id = ' . $id);
            if (!$row)
                {
                    throw new Exception("Count not find row $id");
                }
            return $row->toArray();
        }
            
        //returns list of courses for a single user
        public function getSingleUserCourses($user_id)
        {
            $user_id = (int)$user_id;
            $row = $this->fetchAll('user_id = ' . $user_id);

            if (!$row)
                {
                    throw new Exception("Count not find row $user_id");
                }
            return $row;
        }


        //single course details
        public function getCourseDetails($course_id)
        {
            $course_id = (int)$course_id;
            $row = $this->fetchAll('id = ' . $course_id);
            if (!$row)
                {
                    throw new Exception("Count not find row $course_id");
                }
            return $row;
        }



               
	public function addCourse($CourseName, $CourseNumber, $CourseCredits, $desired_grade, $semester, $year, $user_id)
        {

		$data = array (
		 'course_name' => $CourseName,
                 'course_number' => $CourseNumber,
                 'course_credits' => $CourseCredits,
                 'desired_grade' => $desired_grade,
                 'semester' => $semester,
                 'year' => $year,
                 'user_id' => $user_id,

                 
		);
		$this->insert($data);
	}

       
        public function updateCourse($course_id,$CourseName, $CourseNumber, $CourseCredits, $desired_grade,$semester, $year)
        {
            $data = array (
                 'id' => $course_id,
                 'course_name' => $CourseName,
                 'course_number' => $CourseNumber,
                 'course_credits' => $CourseCredits,
                 'desired_grade' => $desired_grade,
                 'semester' => $semester,
                'year' => $year,
                
		);

            $this->update($data, 'id = '. (int)$course_id);
        }


        public function deleteCourse($id)
        {
            $this->delete('id =' . (int)$id);
        }

}